package com.yx.gifts.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by yx on 2017/6/2.
 */

public class GiftViewPagerAdapter extends PagerAdapter {
    private List<View> pageview;// 显示的页面
    // private Context context;

    public GiftViewPagerAdapter(List<View> pageview) {
        //this.context = context;
        this.pageview = pageview;
    }

    public void onRefresh() {
        if (pageview != null && pageview.size() > 0) {
            pageview.clear();
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return pageview.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {//销毁Item
        if (position > pageview.size() - 1) return;
        container.removeView(pageview.get(position));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {//实例Item
        container.addView(pageview.get(position), 0);
        return pageview.get(position);
    }
}
